package com.nio.c1_NettyTest;

import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.charset.StandardCharsets;

/**
 * @version No one is coming, unless you change yourself!!!
 * @author： pang-yun
 * @date： 2021-05-31 09:45
 */

public class GatherWritingTest {

    //集中写入  字符串
    public static void main(String[] args) {

        //先编写三个已经存入数据的ByteBuffer
        ByteBuffer hello = StandardCharsets.UTF_8.encode(" hello ");
        ByteBuffer herman = StandardCharsets.UTF_8.encode("herman ");
        ByteBuffer pang = StandardCharsets.UTF_8.encode("  pang");

        //准备通道
        try (FileChannel fileChannel = new RandomAccessFile("GatherWriting.txt", "rw").getChannel()) {
            fileChannel.write(new ByteBuffer[]{hello,herman,pang});

        } catch (IOException e) {
        }

    }
}
